package com.csdj.socket_thread;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class ClientDemo {
    //定义ip地址
    public static final  String IP = "127.0.0.1";
    //定义端口号
    public static final  int PORT = 8888;

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        try {
            //创建客户端Socket对象
            Socket socket = new Socket(IP,PORT);
            //获取输出流，准备数据的发送
            OutputStream os = socket.getOutputStream();
            System.out.print("请输入您要发送的内容信息:");
            String reply = input.next();
            //套接字节输出流，变成字符缓冲流，使操作字符串信息更加方便
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write(reply); //直接发送字符串信息
            bw.flush();//刷新缓冲区域
            bw.close();
            os.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
